<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- 无障碍访问 label -->
    <label for="keywords">keywords</label>
    <!-- autofocus 自动聚焦 -->
    <input type="text" id="keywords" />
    <script>
        const input = document.querySelector('#keywords');
        // 聚焦 
        input.addEventListener('focus', function (event) {
            console.log('focus 表单聚焦事件');
        })

        // input 实时的收集值
        input.addEventListener('input', function () {// keyup keydown input
            console.log(this.value);
        });
        // enter键 
        input.addEventListener('keydown', function () {// keyup keydown input
            // console.log(event.keyCode);
            if (event.keyCode == 13) {
                console.log('提交表单')
            }
        });
    </script>
</body>

</html>